# 评论模块
from model import db
import datetime
from sqlalchemy.dialects.mysql import LONGTEXT


class Comment(db.Model):
    __tablename__ = "comment"  # 映射的数据表，不写默认是类名
    comment_id = db.Column(db.Integer, primary_key=True, nullable=False)
    photo_id = db.Column(db.Integer)
    comment_ip = db.Column(db.String(128), nullable=False)
    comment_time = db.Column(db.DateTime, default=datetime.datetime.now())
    comment_content = db.Column(LONGTEXT, nullable=False)

    def keys(self):
        return ("comment_id", 'photo_id', 'comment_ip', 'comment_time', 'comment_content')

    def __getitem__(self, item):
        return getattr(self, item)